﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace SelfService.DataAccess.Migrations
{
    public partial class 新增支付表 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<string>(
                name: "HisCode",
                table: "SysPatients",
                type: "varchar(64)",
                maxLength: 64,
                nullable: true)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<Guid>(
                name: "PatientId",
                table: "SysOrders",
                type: "char(36)",
                nullable: true,
                collation: "ascii_general_ci");

            migrationBuilder.CreateTable(
                name: "SysPays",
                columns: table => new
                {
                    ID = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    PatientId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    PayTypeId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
                    Amount = table.Column<decimal>(type: "decimal(65,30)", nullable: false),
                    OutOrderId = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    SerialsNumber = table.Column<string>(type: "varchar(128)", maxLength: 128, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    PayStatus = table.Column<int>(type: "int", nullable: false),
                    RefundStatus = table.Column<int>(type: "int", nullable: false),
                    PayTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    CreateBy = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    UpdateTime = table.Column<DateTime>(type: "datetime(6)", nullable: true),
                    UpdateBy = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SysPays", x => x.ID);
                    table.ForeignKey(
                        name: "FK_SysPays_SysPatients_PatientId",
                        column: x => x.PatientId,
                        principalTable: "SysPatients",
                        principalColumn: "ID");
                    table.ForeignKey(
                        name: "FK_SysPays_SysPayTypes_PayTypeId",
                        column: x => x.PayTypeId,
                        principalTable: "SysPayTypes",
                        principalColumn: "ID");
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_SysOrders_PatientId",
                table: "SysOrders",
                column: "PatientId");

            migrationBuilder.CreateIndex(
                name: "IX_SysPays_PatientId",
                table: "SysPays",
                column: "PatientId");

            migrationBuilder.CreateIndex(
                name: "IX_SysPays_PayTypeId",
                table: "SysPays",
                column: "PayTypeId");

            migrationBuilder.AddForeignKey(
                name: "FK_SysOrders_SysPatients_PatientId",
                table: "SysOrders",
                column: "PatientId",
                principalTable: "SysPatients",
                principalColumn: "ID");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_SysOrders_SysPatients_PatientId",
                table: "SysOrders");

            migrationBuilder.DropTable(
                name: "SysPays");

            migrationBuilder.DropIndex(
                name: "IX_SysOrders_PatientId",
                table: "SysOrders");

            migrationBuilder.DropColumn(
                name: "HisCode",
                table: "SysPatients");

            migrationBuilder.DropColumn(
                name: "PatientId",
                table: "SysOrders");
        }
    }
}
